import App from "./App";

// #ifndef VUE3
import Vue from "vue";
import "./uni.promisify.adaptor";
Vue.config.productionTip = false;
App.mpType = "app";

// 引入 vk框架前端
import config from "@/app.config.js";
import store from "@/store/index.js";
import vk from "@/uni_modules/vk-unicloud";

// 按需引入Element UI组件
import {
	Button,
	Select,
	TimePicker,
	Upload,
	Dialog,
	Table,
	TableColumn,
	Empty
} from "element-ui";

// 仅引入需要的CSS
import "element-ui/lib/theme-chalk/button.css";
import "element-ui/lib/theme-chalk/select.css";
import "element-ui/lib/theme-chalk/time-picker.css";
import "element-ui/lib/theme-chalk/upload.css";
import "element-ui/lib/theme-chalk/dialog.css";
import "element-ui/lib/theme-chalk/table.css";
import "element-ui/lib/theme-chalk/table-column.css";
import "element-ui/lib/theme-chalk/empty.css";

// 性能优化配置
Vue.config.performance = true;

// 组件按需注册
const components = [
	Button,
	Select,
	TimePicker,
	Upload,
	Dialog,
	Table,
	TableColumn,
	Empty
];
components.forEach(component => {
	Vue.use(component);
});

// 全局注册zfy方法
import zfy from "@/utils/index.js";
Vue.prototype.zfy = zfy;
Vue.use(vk);

// 初始化 vk框架
Vue.prototype.vk.init({
	Vue,
	config,
});

// 添加全局错误处理
Vue.config.errorHandler = function(err, vm, info) {
	console.error('Vue错误:', err);
	console.error('错误信息:', info);
};

// 添加全局警告处理
Vue.config.warnHandler = function(msg, vm, trace) {
	console.warn('Vue警告:', msg);
	console.warn('警告追踪:', trace);
};

const app = new Vue({
	store,
	...App,
});

app.$mount();
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from "vue";
export function createApp() {
	const app = createSSRApp(App);
	return {
		store,
		app,
	};
}
// #endif